package org.example.sward.tooffer;


public class Offer17 {

    int[] res;
    int count = 0,n;
    char[] num,loop = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    int start,nine = 0;


    public static void main(String[] args) {
        Offer17 offer17 = new Offer17();
        String result = offer17.printNumbers(2);
        System.out.println(result);
    }

    public String printNumbers(int n){
        this.n = n;
        //数字字符串集
        res = new int[(int)Math.pow(10,n) - 1];
        //定义长度为n的字符串列表
        num = new char[n];
        //高位上有几个0
        start = n - 1;

        //开启全排列递归
        dfs(0);

        for(int i : res){
            System.out.println(i);
        }

        return res.toString();
    }

    private void dfs(int x) {
       if(x == n){
           String s = String.valueOf(num).substring(start);
           if(!s.equals("0")){
               res[count++] = Integer.parseInt(s);
           }
           if(n - start == nine){
               start--;
           }
           return;  
       }
       for (char i : loop){
           if(i == '9'){
               nine++;
           }
           num[x] = i;
           dfs(x + 1);
       }
       nine--;

    }


}
